<template>
  <div class="nav-header">
    <el-icon style="margin: auto" size="28" @click="handleFoldClick"
      ><Fold v-if="!isFold" /><Expand v-else-if="isFold"
    /></el-icon>
    <div class="count">
      <LylBreadcumb :breadcrumbs="breadcrumbs" />
      <UserInfo />
    </div>
  </div>
</template>

<script lang="ts" setup>
import LylBreadcumb from '@/base-ui/breadcrumb/src/breadcumb.vue'
import { useStore } from '@/store'
import { pathMapBreadcrumbs } from '@/utils/map-menus'
import { Expand, Fold } from '@element-plus/icons-vue'
import { ref, defineEmits, computed } from 'vue'
import { useRoute } from 'vue-router'
import UserInfo from './user-info.vue'

const breadcrumbs = computed(() => {
  const store = useStore()
  const userMenus = store.state.login.userMenus
  const route = useRoute()
  const currentPath = route.path
  return pathMapBreadcrumbs(userMenus, currentPath)
})
const isFold = ref(false)
const emit = defineEmits(['foldChange'])
const handleFoldClick = () => {
  isFold.value = !isFold.value
  emit('foldChange', isFold.value)
}
</script>

<style scoped lang="less">
.nav-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  .count {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1;
    padding: 0 20px;
  }
}
</style>
